/**
 * 弹窗特效
 */
export namespace DialogEffect {
    //此处枚举使用字符串 编辑器显示不出来
    export enum EffectType {
        NoEffect,
        MoveFromLeft,
        MoveFromRight,
        MoveFromTop,
        MoveFromBottom,
        MoveFromCenter,
    }
    export function getName(type: number) {
        let name: string;
        switch (type) {
            case DialogEffect.EffectType.NoEffect:
                name = 'NoEffect'
                break;
            case DialogEffect.EffectType.MoveFromLeft:
                name = 'MoveFromLeft'
                break;
            case DialogEffect.EffectType.MoveFromRight:
                name = 'MoveFromRight'
                break;
            case DialogEffect.EffectType.MoveFromTop:
                name = 'MoveFromTop'
                break;
            case DialogEffect.EffectType.MoveFromBottom:
                name = 'MoveFromBottom'
                break;
            case DialogEffect.EffectType.MoveFromCenter:
                name = 'MoveFromCenter'
                break;
        }
        return name;
    }
    export class NoEffect {
        static show(layer: cc.Node) {

        }
        static hide(layer: cc.Node) {
            
        }
    }
    export class MoveFromCenter {
        static async show(layer: cc.Node) {
            return new Promise((resolve, reject) => {
                cc.tween(layer)
                    .set({ scale: 0.5 })
                    .to(0.3, {
                        scale: 1,
                        opacity: 255
                    }, {
                        easing: 'backOut'
                    })
                    .call(() => {
                        resolve(null)
                    })
                    .start()
            })
        }
        static async hide(layer: cc.Node) {
            return new Promise((resolve, reject) => {
                cc.tween(layer)
                    .to(0.3, {
                        scale: 0.5,
                        opacity: 0
                    }, {
                        easing: 'backIn'
                    })
                    .call(() => {
                        resolve(null)
                    })
                    .start()
            })
        }
    }

    export class MoveFromLeft {
        static async show(layer: cc.Node) {
            return new Promise((resolve, reject) => {
                cc.tween(layer)
                    .set({ position: cc.v3(-cc.winSize.width * 1.5, 0) })
                    .to(0.3, { position: cc.v3(0, 0) })
                    .call(() => {
                        resolve(null)
                    })
                    .start()
            })
        }
        static async hide(layer: cc.Node) {
            return new Promise((resolve, reject) => {
                cc.tween(layer)
                    .to(0.3, { position: cc.v3(-cc.winSize.width * 1.5, 0) })
                    .call(() => {
                        resolve(null)
                    })
                    .start()
            })
        }
    }

    export class MoveFromRight {
        static async show(layer: cc.Node) {
            return new Promise((resolve, reject) => {
                cc.tween(layer)
                    .set({ position: cc.v3(cc.winSize.width * 1.5, 0) })
                    .to(0.3, { position: cc.v3(0, 0) })
                    .call(() => {
                        resolve(null)
                    })
                    .start()
            })
        }
        static async hide(layer: cc.Node) {
            return new Promise((resolve, reject) => {
                cc.tween(layer)
                    .to(0.3, { position: cc.v3(cc.winSize.width * 1.5, 0) })
                    .call(() => {
                        resolve(null)
                    })
                    .start()
            })
        }
    }
    export class MoveFromTop {
        static async show(layer: cc.Node) {
            return new Promise((resolve, reject) => {
                cc.tween(layer)
                    .set({ position: cc.v3(0, cc.winSize.height * 1.5) })
                    .to(0.3, { position: cc.v3(0, 0) })
                    .call(() => {
                        resolve(null)
                    })
                    .start()
            })
        }
        static async hide(layer: cc.Node) {
            return new Promise((resolve, reject) => {
                cc.tween(layer)
                    .to(0.3, { position: cc.v3(0, cc.winSize.height * 1.5) })
                    .call(() => {
                        resolve(null)
                    })
                    .start()
            })
        }
    }

    export class MoveFromBottom {
        static async show(layer: cc.Node) {
            return new Promise((resolve, reject) => {
                cc.tween(layer)
                    .set({ position: cc.v3(0, -cc.winSize.height * 1.5) })
                    .to(0.3, { position: cc.v3(0, 0) })
                    .call(() => {
                        resolve(null)
                    })
                    .start()
            })
        }
        static async hide(layer: cc.Node) {
            return new Promise((resolve, reject) => {
                cc.tween(layer)
                    .to(0.3, { position: cc.v3(0, -cc.winSize.height * 1.5) })
                    .call(() => {
                        resolve(null)
                    })
                    .start()
            })
        }
    }
}
